// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 

package webserver;

import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.Hashtable;

// Referenced classes of package org.jibble.simplewebserver:
//            RequestThread

public class SimpleWebServer extends Thread
{

    public SimpleWebServer(File file, int i)
        throws IOException
    {
        _running = true;
        _rootDir = file.getCanonicalFile();
        if(!_rootDir.isDirectory())
        {
            throw new IOException("Not a directory.");
        } else
        {
            _serverSocket = new ServerSocket(i);
            start();
            return;
        }
    }

    public void run()
    {
        while(_running) 
            try
            {
                java.net.Socket socket = _serverSocket.accept();
                RequestThread requestthread = new RequestThread(socket, _rootDir);
                requestthread.start();
            }
            catch(IOException ioexception)
            {
                System.exit(1);
            }
    }

    public static String getExtension(File file)
    {
        String s = "";
        String s1 = file.getName();
        int i = s1.lastIndexOf(".");
        if(i >= 0)
            s = s1.substring(i);
        return s.toLowerCase();
    }

    public static void main(String args[])
    {
        SimpleWebServer simplewebserver;
        try
        {
            simplewebserver = new SimpleWebServer(new File("./"), 80);
        }
        catch(IOException ioexception)
        {
            System.out.println(ioexception);
        }
    }

    public static final String VERSION = "SimpleWebServer  http://www.jibble.org/";
    public static final Hashtable MIME_TYPES;
    private File _rootDir;
    private ServerSocket _serverSocket;
    private boolean _running;

    static 
    {
        MIME_TYPES = new Hashtable();
        String s = "image/";
        MIME_TYPES.put(".gif", s + "gif");
        MIME_TYPES.put(".jpg", s + "jpeg");
        MIME_TYPES.put(".jpeg", s + "jpeg");
        MIME_TYPES.put(".png", s + "png");
        String s1 = "text/";
        MIME_TYPES.put(".html", s1 + "html");
        MIME_TYPES.put(".htm", s1 + "html");
        MIME_TYPES.put(".txt", s1 + "plain");
    }
}
